package br.com.drestranho.escola.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import br.com.drestranho.escola.entity.ChamadaItem;

@Stateless
public class ChamadaItemDAO {
	@PersistenceContext(unitName="H6Escola")
	private EntityManager em;
	
	public void salvar(ChamadaItem bean) {
		em.persist(bean);
	}
	
	public void atualizar(ChamadaItem bean) {
		em.merge(bean);
	}
	
	public void remover( ChamadaItem bean) {
		em.remove(em.merge(bean));
	}
	
	public ChamadaItem getBean(Integer id) {
		ChamadaItem bean = em.find(ChamadaItem.class, id);
		return bean;
	}
	
	public List<ChamadaItem> getBeans(){//Lista 
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<ChamadaItem> cq = cb.createQuery(ChamadaItem.class);
		Root<ChamadaItem> from = cq.from(ChamadaItem.class);
		CriteriaQuery<ChamadaItem> select = cq.select(from);
		List<ChamadaItem> ChamadaItems = em.createQuery(select).getResultList();
		return ChamadaItems;
	}
	
}
